#ifndef UTIL_H
#define UTIL_H

#include <cstdlib>
#include <ctime>

namespace Util {
	static int* copyArray( int *src, int size );
	static double* copyArray( double *src, int size );
	static char* copyArray( const char *src, int size );

	template <class T>
	static T* copyArray( const T *src, int size ) {
		T *copy = new T[size];
		for (int i = 0; i < size; i++)
			copy[i] = src[i]; 

		return copy;
	}

	template <class T>
	static T* newArray( int size ) {
		T *v = new T[size];
		return v;
	}

	template <class T>
	static T** newMatrix( int n, int m ) {
		T **v = new T*[n];
		for (int i = 0; i < n; i++)
			v[i] = new T[m];

		return v;
	}

	static int random( int min, int max, double *w = NULL );
	static int random( int *v, int n, double *w = NULL );
	static double random( double min, double max );

	static int map( int i, int j, int maxj );
};

#endif